<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-购物车</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_user.css">

	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_index.js"></script>
    <script src="/resource/js/T.js"></script>
	<script>
		$(function(){
			var popup = '<div class="popup"></div><div class="popup-show">';
		        popup += '<div class=\"popup-p\">';
		        popup +='<i><img src=\"/resource/img/gl_show_err.png\" alt=""></i>';
		        popup +='<div class=\"left\">';           
		        popup +='是否删除选中的商品？<br/>';                 
		        popup +='<div class="btn"><a href="javascript:;" class="deter">确定</a>';
		        popup +='<a href="javascript:;" class="close">取消</a></div>';                 
		        popup +='</div><div class=\"popup-close\"></div></div></div>';

            $('body').append(popup);
		    $('.popup-show').css('margin-left',-$('.popup-show').width()/2);
		    $(document).delegate('.info .del','click',function(){
                var cart_id = $(this).attr('data-cart_id');
		    	$('.popup-show').show();
		    	$('.popup').show();
                $('.popup-show .deter').attr('cart_id',cart_id);
		    });
            //点击删除选中
            $('.delete_').click(function(){
                var $checkbox = $('input[type="checkbox"]');
                var cart_id = [];
                for (var i = 0; i < $checkbox.length; i++) {
                    if (typeof($checkbox.eq(i).attr('cart-id')) != 'undefined') {
                        if($checkbox[i].checked){
                            cart_id.push($checkbox.eq(i).attr('cart-id'));
                        };
                    }
                };
                $('.popup-show').show();
                $('.popup').show();
                $('.popup-show .deter').attr('cart_id',cart_id);
            });
            $(document).delegate('.popup-show .deter','click',function(){
                var cart_id = $(this).attr('cart_id');
                $.ajax({
                    url: "/shop_cart_delete",
                    type: "get",
                    data: 'cart_id='+cart_id,
                    success: function (msg) {
                        $('.popup-show').hide();
                        $('.popup').hide();
                        if(msg){
                            $.ajax({
                                url: "/shop_cart_ajax",
                                type: "get",
                                success: function (msg) {
                                    $('#list').html(msg);
                                }
                            });
                        }
                    }
                });
            });
		});
	</script>
</head>
<body>
<div class="head">
    @include('common.user_head')
</div>
<div class="user-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<div><span>购物车</span>
			</div>
		</div>
	</div>
</div>	
<!-- 无商品 -->
@if($count==0)
 <div class="shopping">
	<div class="main">
		<div class="shopping-no">
			<div class="box">
				<i></i>
				<span>购物车内没有商品。</span>
				<a href="/shopping">去商城选购&#62;&#62;</a>
			</div>
		</div>
	</div>
</div>
@else
<!-- you商品 -->
<div class="shopping">
	<div class="main" id="list">
		<div class="title">全部商品{{$count}}个</div>
		<div class="table" >
			<table>
				<thead>
					<tr>
						<th width="70px"><input type="checkbox" class="check-all" id="check-all" checked>全选</th>
						<th width="260px">商品信息</th>
						<th width="120px">钢厂</th>
						<th width="130px">单价</th>
						<th width="130px">件重</th>
						<th width="90px">件数</th>
						<th width="165px">数量</th>
						<th width="145px">合计</th>
						<th width="">操作</th>
					</tr>
					<tr>
						<th colspan="9" class="bg"></th>
					</tr>
				</thead>
                @foreach($data as $v)
				<tbody>
					<tr class="first">
						<td colspan="9">
							<input type="checkbox" class="check-bus" checked>{{$v->storage_city}} {{$v->storage_name}}
							<span>地址：{{$v->storage_address}}</span>
							<span>联系电话：{{$v->storage_phone}}</span>
						</td>
					</tr>
                    @foreach($v->cart_info as $vv)
					<tr class="info" stock="{{$vv->useable_stock}}">
						<td><div><input type="checkbox" cart-id="{{$vv->cart_id}}" checked></div></td>
						<td><div>{{$vv->brand_name}}   {{$vv->m_name}}   {{$vv->product_spec}}</div></td>
						<td><div>{{$vv->storage_name}}</div></td>
						<td><div class="price">￥{{$vv->product_price}}</div></td>
						<td><div class="w_per_piece">{{$vv->piece_weight}}吨/件</div></td>
						<td><div>{{$vv->useable_stock}}</div></td>
						<td>
							<div class="info-num">
								<a href="javascript:;" class="pre"></a>
								<input type="text" id="info-num" value="{{$vv->number}}" product_id="{{$vv->product_id}}" class="number">
								<a href="javascript:;" class="next"></a>
							</div>
						</td>
						<td><div class="total"><span>￥{{round($vv->product_price*$vv->number*$vv->piece_weight,2)}}</span></div></td>
						<td><a href="javascript:;" class="del" data-cart_id="{{ $vv->cart_id }}">删除</a></td>
					</tr>
                    @endforeach
					<tr class="bg">
						<td colspan="9"></td>
					</tr>
				</tbody>
                    @endforeach
			</table>
			<div class="statistics">
				<div class="function left">
					<input type="checkbox" class="check-all" id="check-all" checked>全选
					<a href="javascript:;" class="delete delete_">删除选中的商品</a>
				</div>
				<div class="go right">
					@if(!empty($data))
					<a href="javascript:;" id="cart-submit">去下单</a>
					@else
					@endif
				</div>
				<div class="sta-mon right">
					商品总金额（不含运费）: <span>￥{{round($sum[0]->price,2)}}</span>
				</div>
				<div class="sta-num right">
					商品重量小计：共 <span>{{$sum[0]->num}}</span> 件  {{round($sum[0]->weight,3)}}吨
				</div>
			</div>
		</div>
	</div>
</div>
@endif
@include('common.shop_foot')
</body>
</html>